﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DelonixRegiaHMSys.Core.Interfaces;
using DelonixRegiaHMSys.Core.Models;

namespace DelonixRegiaHMSys.Infrastructure.Data
{
    public class EfGuestCreditCardDetails : IGuestCreditCardDetailsQuery
    {
        //public IEnumerable<GuestCreditCardDetails> GetAll()
        //{
        //    var context = new hmsDBEntities();
        //    return context.guestCreditCardDetails.Select(gcc => new GuestCreditCardDetails()
        //    {
        //        CreditCardNum = gcc.creditCardNum,
        //        CardHolderName = gcc.cardholderName,
        //        GuestID = gcc.guestID,
        //        CardType = gcc.cardType,
        //        CardExpirationDate = gcc.cardExpirationDate

        //    });

        //}
        public void AddCreditCardDetail(GuestCreditCardDetails gccd)
        {
            var context = new hmsDBEntities();
            var newCreditCardDetails = context.guestCreditCardDetails.Create();
            newCreditCardDetails.creditCardNum = gccd.CreditCardNum;
            newCreditCardDetails.cardholderName = gccd.CardHolderName;
            newCreditCardDetails.guestID = gccd.GuestID;
            newCreditCardDetails.cardType = gccd.CardType;
            newCreditCardDetails.cardExpirationDate = gccd.CardExpirationDate;
            context.guestCreditCardDetails.Add(newCreditCardDetails);
            context.SaveChanges();
        }
        public void DeleteCreditCardDetail(string creditCardNum)
        {
            var context = new hmsDBEntities();
            var creditcarddetailsToDelete = context.guestCreditCardDetails.FirstOrDefault(d => d.creditCardNum == creditCardNum);
            context.guestCreditCardDetails.Remove(creditcarddetailsToDelete);
            context.SaveChanges();
        }
    }
}
